#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Datetime: 2022/9/26 11:17
# @Author  : CHENWang
# @Site    : 
# @File    : weekly_get_exchange_margin_interest_rate.py
# @Software: PyCharm

"""
脚本说明: get_exchange_margin_interest_rate 每周运行
"""

from TQR_Applications.factor_database.crypto.trading_data_update import (get_exchange_margin_interest_rate,
                                                                         get_lend_borrow_fee_rate_v1,get_aave_borrow_fee_rate_v1)
from logger import logger
import os
import traceback
from task_monitor import task_to_db, send_error_to_email


if __name__ == '__main__':
    logger.info("开始get_exchange_margin_interest_rate")
    task_to_db(os.path.basename(__file__), 'get_exchange_margin_interest_rate')
    try:
        get_exchange_margin_interest_rate()
        task_to_db(os.path.basename(__file__), 'get_exchange_margin_interest_rate', 1)
    except Exception as e:
        msg = traceback.format_exc()
        logger.info(msg)
        send_error_to_email(script_name=os.path.basename(__file__), func_name="get_exchange_margin_interest_rate", message=msg)
        # raise e
    logger.info("成功get_exchange_margin_interest_rate")

    logger.info("开始get_lend_borrow_fee_rate_v1")
    task_to_db(os.path.basename(__file__), 'get_lend_borrow_fee_rate_v1')
    try:
        get_lend_borrow_fee_rate_v1()
        task_to_db(os.path.basename(__file__), 'get_lend_borrow_fee_rate_v1', 1)
    except Exception as e:
        msg = traceback.format_exc()
        logger.info(msg)
        send_error_to_email(script_name=os.path.basename(__file__), func_name="get_lend_borrow_fee_rate_v1", message=msg)
        # raise e
    logger.info("成功get_lend_borrow_fee_rate_v1")

    logger.info("开始get_aave_borrow_fee_rate_v1")
    task_to_db(os.path.basename(__file__), 'get_aave_borrow_fee_rate_v1')
    try:
        get_aave_borrow_fee_rate_v1()
        task_to_db(os.path.basename(__file__), 'get_aave_borrow_fee_rate_v1', 1)
    except Exception as e:
        msg = traceback.format_exc()
        logger.info(msg)
        send_error_to_email(script_name=os.path.basename(__file__), func_name="get_aave_borrow_fee_rate_v1", message=msg)
        # raise e
    logger.info("成功get_aave_borrow_fee_rate_v1")